package com.fasteat.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Description:ElasticSearch配置
 * @author ghost
 * *@since 2021-2-8
 */
@Configuration
public class ElasticSearchConfig {

	@Autowired
	private MyElasticSearchProperties myElasticSearchProperties;



	@Bean
	public RestHighLevelClient restHighLevelClient() {
		return new RestHighLevelClient(
				RestClient.builder(httpHost(
						myElasticSearchProperties.getHostname(),
						myElasticSearchProperties.getPort(),
						myElasticSearchProperties.getProtocol())));
	}


	private HttpHost httpHost(String hostname, int port, String protocol) {
		return new HttpHost(hostname, port, protocol);
	}


}